var t = require("../../../@babel/runtime/helpers/createForOfIteratorHelper"), o = getApp(), a = require("../../../mycomponent/yz_pay/yz_pay");

Page({
    behaviors: [ a ],
    data: {
        status: 1,
        resultImg: "",
        content: null,
        buttons: [],
        pay_type: null,
        showPay: !1,
        money: "",
        ordersn: "",
        loading: !0,
        fieldStatus: 0,
        field: [],
        form_data: null,
        thumb: "",
        description: "",
        showSign: !1
    },
    onLoad: function(t) {
        this.getData();
    },
    getData: function() {
        var t = this;
        this.setData({
            resultImg: null
        });
        var a = o.getNetAddresss("plugin.hand-sign-protocol.frontend.controllers.protocol.getDetail");
        o._postNetWork({
            url: a,
            data: {
                id: this.options.id
            },
            success: function(o) {
                var a = o.data;
                1 == a.result ? t.setData({
                    content: a.data.protocol.content,
                    money: a.data.protocol.amount,
                    status: a.data.protocol.sign_status,
                    resultImg: a.data.protocol.sign_status ? a.data.protocol.img_url : null,
                    loading: !1,
                    fieldStatus: a.data.form.status,
                    field: a.data.form.fields,
                    thumb: a.data.form.thumb,
                    description: a.data.form.description
                }) : wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    submit: function(t) {
        t && (this.data.form_data = t.detail), this.singConfirm();
    },
    singConfirm: function(t) {
        (t && (this.data.resultImg = t.detail), 0 == Object.keys(this.data.field).length || this.data.form_data) ? this.data.payMethods && this.data.payMethods.length > 0 && this.data.resultImg ? this.setData({
            showPay: !0
        }) : this.getPayButton() : this.selectComponent("#diyform").submit();
    },
    hiddenSign: function() {
        this.setData({
            showSign: !0
        });
    },
    openSign: function() {
        this.setData({
            showSign: !1
        });
    },
    getPayButton: function() {
        var a = this, n = o.getNetAddresss("plugin.hand-sign-protocol.frontend.controllers.protocol.getButtons");
        o._postNetWork({
            url: n,
            data: {
                id: this.options.id
            },
            success: function(o) {
                var n = o.data;
                if (1 == n.result) {
                    if (0 == Number(a.data.money)) return void a.payFee({
                        currentTarget: {
                            dataset: {
                                type: 54
                            }
                        }
                    });
                    var e, s = t(n.data.buttons);
                    try {
                        for (s.s(); !(e = s.n()).done; ) {
                            var i = e.value;
                            i._iconClassName = a.btnclass(i.value);
                        }
                    } catch (t) {
                        s.e(t);
                    } finally {
                        s.f();
                    }
                    a.setData({
                        payMethods: n.data.buttons,
                        showPay: !0
                    });
                } else wx.showToast({
                    icon: "none",
                    title: n.msg,
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    payFee: function(t) {
        var a = this, n = t.currentTarget.dataset.type, e = o.getNetAddresss("plugin.hand-sign-protocol.frontend.controllers.protocol.pay");
        o._postNetWork({
            url: e,
            data: {
                pay_type: n,
                img_url: this.data.resultImg,
                id: this.options.id,
                form_data: this.data.form_data,
                client_type: 2
            },
            success: function(t) {
                var o = t.data;
                if (1 == o.result) {
                    var e = o.data, s = e.config, i = e.order_sn;
                    if (i || wx.showToast({
                        icon: "none",
                        title: "参数错误",
                        duration: 1500
                    }), 54 == n) return void (o.data.line ? wx.navigateTo({
                        url: o.data.line,
                        fail: function(t) {
                            this.getData();
                        }
                    }) : a.getData());
                    a.rechargePay(n, s, i, "credit");
                } else wx.showToast({
                    icon: "none",
                    title: o.msg,
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    onClose: function() {
        this.setData({
            showPay: !1
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});